package hEdge;

import java.awt.geom.Line2D;

import processing.core.PVector;


public class DelaunayMath {
	static double minValue=0.000000001;
	
	public final static int CWRIGHT = 1;
	public final static int CCWLEFT = -1;
	public final static int PARALLEL = 0;
	public static boolean isOnline(PVector a, PVector b, PVector p){
		
		double d=Line2D.ptSegDist(a.x, a.y, b.x, b.y, p.x, p.y);
		if (d<0.001)return true;
		return false;
	}
	public static boolean isConvex(PVector a, PVector b, PVector c, PVector d) {
		// points online = already concave
		if (relativeCCW(a, b, c) != CCWLEFT)
			return false;
		if (relativeCCW(b, c, d) != CCWLEFT)
			return false;
		if (relativeCCW(c, d, a) != CCWLEFT)
			return false;
		if (relativeCCW(d, a, b) != CCWLEFT)
			return false;
		return true;
	}
	public static int relativeCCW(PVector p0, PVector p1, PVector p2) {
		PVector v1=PVector.sub(p0, p1);
		PVector v2=PVector.sub(p0, p2);
		double cA= ((v1.x) * (v2.y) - (v2.x) * (v1.y));
		if (Math.abs(cA)<minValue)return 0;
		if (cA<0)return CWRIGHT;
		return  CCWLEFT;
	}
	
	public static double parallelArea(PVector p0, PVector p1, PVector p2) {
		PVector v1 = PVector.sub(p0, p1);
		PVector v2 = PVector.sub(p0, p2);
		return ((v1.x) * (v2.y) - (v2.x) * (v1.y));
	}
	public static float distSqr(PVector p0,PVector p1) {
		float dX=p0.x-p1.y;
		float dY=p0.x-p1.y;
		return dX*dX+dY*dY;
	}
}
